﻿using System;
using Mvc.XForms.Actions.Settings;

namespace Mvc.XForms.Actions {
	public class ActionDelete<TContext> : IActionDelete<TContext> {
		public ActionDelete() {
			Settings = new ActionDeleteSettings<TContext>(this);

			// Set defaults
			At = At.Current;
			Nodeset = string.Empty;
			Event = XFormEvent.DOMActivate;
		}

		public ActionDeleteSettings<TContext> Settings { get; private set; }
		public XFormAction Action {
			get { return XFormAction.Delete; }
		}
		public XFormEvent Event { get; set; }
		public string Nodeset { get; set; }
		public At At { get; set; }
		public string If { get; set; }
		// Not currently implemented
		public string While { get; set; }

		public object ToJson() {
			var json = new {
				type = (int)Action,
				ev = Event.ToScriptName(),
				ns = Nodeset,
				at = (int)At,
				cond = If
			};
			return json;
		}
	}
}